package com.zn.opit.videoframe.controller;

import com.zn.opit.videoframe.service.MinioService;
import com.zn.opit.videoframe.utils.VideoUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@Slf4j
@RequestMapping("video")
@RestController
public class VideoController {

    @Resource
    private MinioService minioService;

    // 上传视频
    @PostMapping("/uploadVideo")
    public String uploadVideo(MultipartFile file) {
        String filename = minioService.upload(file);
        log.info("视频 {} 上传成功！", filename);
        MultipartFile firstFrame = VideoUtil.getFirstFrame(file);
        String firstFrameFilename = minioService.upload(firstFrame);
        log.info("封面 {} 上传成功！", firstFrameFilename);
        return filename;
    }
}
